public class TestSink extends Sink {
public TestSink(Sink next) { this.next = next; }
public Stack<Choicepoint> fishFor(String name, int arity, Compound term, int choice, Prolog prolog, Unifier unifier, int cutIndex, Stack<Conjunct> continuation, Stack<Choicepoint> choicepoints) {
Choicepoint choicepoint;
int height = choicepoints.height;
if(arity == 1 && name.equals("flip")) {
switch(choice) {
case 0: {
Compound t1 = new Compound("heads");
Compound t0 = new Compound("flip", t1);
if(unifier.unify(t0,term)) {
choicepoint = new Choicepoint(continuation,height);
choicepoint.bindings = unifier.bound;
return new Stack<Choicepoint>(choicepoint,choicepoints);
}
break;
}
case 1: {
Compound t1 = new Compound("tails");
Compound t0 = new Compound("flip", t1);
if(unifier.unify(t0,term)) {
choicepoints.head.query = choicepoints.head.query.tail;
choicepoints.head.addBindings(unifier.bound);
return choicepoints;
}
break;
}
default: choicepoints.head.dead = true;
}
return choicepoints;
}
return next.fishFor(name,arity,term,choice,prolog,unifier,cutIndex,continuation,choicepoints);
}
}
